package com.itzmn.newcode.offer;

/**
 * @Author: 张梦楠
 * @Date: 2018/11/17 13:15
 * 简书：https://www.jianshu.com/u/d611be10d1a6
 * 码云：https://gitee.com/zhangqiye
 * @Description: 剑指Offer得到两个链表的第一个公共节点
 *
 */
public class GetTwoLinkedListNode {


    public static void main(String[] args) {

    }

    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {


        while (pHead1 !=pHead2 ){

            pHead1 = pHead1==null?pHead2:pHead1.next;
            pHead2 = pHead2==null?pHead1:pHead2.next;
        }

        return pHead1;
    }
    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }


}
